package cn.wsxiot.jxl;

import java.io.File;

import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class Create {

    /**
     * JXL创建Excel文件
     * 第一个运行
     * @param args
     */
    public static void main(String[] args) {
        String[] title = {"id","name","sex"};
        //创建Excel文件
        File file = new File("jxl_test.xls");
        try {
            if(!file.exists()){
                file.createNewFile();
            }
            //创建可写工作簿
            WritableWorkbook workbook = Workbook.createWorkbook(file);
            //创建一个可写sheet
            WritableSheet sheet = workbook.createSheet("sheet1", 0);//第0号sheet页，名字为sheet1
            //WritableSheet sheet = workbook.getSheet(0);
            //一个小矩形就是一个label
            Label label = null;
            //第一行设置列名
            for (int i = 0; i < title.length; i++) {
                label = new Label(i,0,title[i]);//列号，行号，内容
                sheet.addCell(label);
            }
            //追加数据
            for (int i = 1; i < 10; i++) {
                label = new Label(0,i,"a" + i);
                sheet.addCell(label);
                label = new Label(1,i,"user" + i);
                sheet.addCell(label);
                label = new Label(2,i,"男");
                sheet.addCell(label);
            }
            //写入数据
            workbook.write();
            workbook.close();

        } catch (Exception e) {
            e.printStackTrace();
        }




    }

}